package com.ll.blog.common;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.ll.blog.contant.Constant;
import com.ll.blog.entity.User;

import java.util.Date;

public class Token {
    public static String  createJWT(User user) {
        Algorithm algorithm = Algorithm.HMAC256(Constant.JWT_KEY);
        return JWT.create().withClaim("username", user.getUsername())
                .withClaim(Constant.user_id, user.getId())
                .withClaim(Constant.role, user.getRole())
                .withExpiresAt(new Date(System.currentTimeMillis() + 6*60*60*1000))
                .sign(algorithm);
    }
}
